home *** CD-ROM | disk | FTP | other *** search
- /* sample of POE and help */
-
- #include <stdio.h>
- #include <string.h>
- #include <bios.h>
- #include "wwindefs.h" /* window headers */
- #include "wwinstpr.h" /* window structures/prototypes */
-
- void LoadLabels(); /* internal subroutines */
- int Process();
- void NameHelp(unsigned char helpitem);
- void ShiftWindow(struct WWinstruc *winptr, unsigned char scan);
-
-
- extern WWVIDMEM WWscreenp; /* pointer to screen memory */
- extern unsigned int WWScreenLength; /* access to WW defaults */
- extern unsigned int WWScreenWidth;
-
-
- /* define caption window - globally */
- struct WWinstruc Caption =
- {"Caption",20,3,10,60, WHITE,BLACK,SLN_BDR,WHITE,BLACK,INV_CSR};
-
- /* define the menu window */
- struct WWinstruc Name =
- {"Name",4,8,4,63, RED,WHITE,SLN_BDR,WHITE,RED,INV_CSR};
-
-
- /* define the points of entry for the Name window*/
- struct WWinPOE NamePOEs[] ={
- {2,10,1,BLACK,NC,'1'}, /* titles */
- {2,20,1,BLACK,NC,'1'},
- {2,30,1,BLACK,NC,'1'},
- {2,40,1,BLACK,NC,'1'},
- {2,50,1,BLACK,NC,'1'},
- {4,20,20,BLUE,NC,'N'}, /* first name */
- {5,20,20,BLUE,NC,'N'}, /* last name */
- {7,20,4,BLACK,NC,'M'}, /* OK */
- {7,40,8,BLACK,NC,'M'}, /* cancel */
- {0,0,0,0,0,0} }; /* dummy */
-
- main()
- {
- int i, rc;
- WWscreenp = WWCOLMEM; /* unecessary - color screen memory is default */
- for (i=0;i<27;i++) /* clear screen */
- printf(" "
- " ");
- if ((rc = WWinDef(&Caption)) !=0) /* set up caption screen */
- {printf("out of memory"); exit(1);}
-
- WWinLoad(&Caption,1,2,NC,NC,"Press F1 for Help",0);
- WWinLoad(&Caption,2,2,NC,NC,"Choose Cancel to exit this program",0);
- WWinPut(&Caption);
- WWinCurSet(&Caption,1,1); /* set cursor out of the way */
-
- LoadLabels(); /* put the labels in the window */
- do
- {
- rc = Process(); /* process the window */
- }
- while (rc != 27);
- Caption.Cursor = NRM_CSR; /* set cursor back to normal */
- WWinCurSet(&Caption,Caption.UseLength,1); /* restore cursor */
- }
-
-
-
-
- void LoadLabels()
- /* this function loads the window with labels for the POEs.
- * Each label is followed by a blank and a 2-digit number which
- * is the offset of the beginning of the POE to the beginning of the
- * label.
- */
- {
- unsigned char *LabelPOEs[] =
- { " Mr. [ ] 07", /* POE starts inside the box */
- " Mrs. [ ] 08",
- " Miss [ ] 08",
- " Ms. [ ] 07",
- " Dr. [ ] 07",
- " First Name : 15",
- " Last Name : 15",
- " OK 01",
- " Cancel 01"};
-
- int i, j, k, rc;
-
- if ((rc = WWinDef(&Name)) !=0)
- {printf("out of memory"); exit(1);}
- /* load labels for every POE up to the dummy */
- for (i=0;(NamePOEs[i].len) != 0;i++)
- {
- k = strlen(LabelPOEs[i]); /* assigned for easy reading */
- j = atoi(LabelPOEs[i]+(k-2)); /* calc offset */
- WWinLoad(&Name,NamePOEs[i].row, NamePOEs[i].col-j+1,NC,NC,
- LabelPOEs[i],k-3);
- }/*for i*/
- }
-
-
-
- int Process()
- /* this function handles the presentation of the POE
- * and any verification
- */
- {
- struct WWinRC retcde;
- char titlehold, *Title[5] = {"Mr.","Mrs.","Miss","Ms.","Dr."};
- char firstname[21],secondname[21], fullname[50];
- int i, activeitem, count, error, done;
-
- done = 0;
- activeitem = 1; /* start with first item */
- while (!done) /* loop till done != 0 */
- {
- WWinPut(&Name);
- do
- {
- retcde = WWinDoPOE(&Name,NamePOEs,activeitem);
- activeitem = retcde.exval;
- if ( (retcde.ascii == 13) /* if ENTER key pressed */
- && (NamePOEs[retcde.exval-1].type != 'M') ) /* but not a menu item */
- retcde.ascii = 0; /* ignore it */
- if (retcde.scan == 59)
- NameHelp(retcde.exval); /* get help */
- if ( ((retcde.stat & 0x03) != 00) /* Shift key */
- && (retcde.ascii == 0) ) /* control key */
- ShiftWindow(&Name,retcde.scan);
-
- }
- while (retcde.ascii == 0); /* require OK or ESC or Cancel */
-
- if ( (retcde.ascii == 27)
- || (retcde.exval == 9) ) /* ESC or Cancel - */
- return(27); /* get out */
-
- /* ENTER was pressed - - validate entries */
- error = 0; /* start clean */
- /* check titles */
- count = 0; /* count number chosen */
- for (i=0;NamePOEs[i].type == '1';i++)
- {
- WWinRead(&Name, NamePOEs[i].row, NamePOEs[i].col, &titlehold, 1);
- if (titlehold != ' ')
- {
- strcpy(fullname,"-");
- strcat(fullname,Title[i]);
- count++;
- }
- }
- if (count != 1) /* if error, load error msg and set error switch */
- {
- WWinLoad(&Name,8,15,BLUE,NCB,"Choose ONE and only ONE Title ",0);
- error = 1;
- }
-
- if (!error) /* continue checking only if no errors */
- {
- /* check names */
- /* can't read to a blank becuase names may
- contain blanks */
- WWinRead(&Name, NamePOEs[5].row, NamePOEs[5].col,
- firstname,NamePOEs[5].len);
- WWinRead(&Name, NamePOEs[6].row, NamePOEs[6].col,
- secondname,NamePOEs[6].len);
- /* strip ending blanks */
- while (firstname[strlen(firstname)-1] == ' ')
- firstname[strlen(firstname)-1] = '\0';
- while (secondname[strlen(secondname)-1] == ' ')
- secondname[strlen(secondname)-1] = '\0';
- /* must be some non-blanks in the names */
- if ( (firstname[0] == '\0') || (secondname[0] == '\0') )
- {
- WWinLoad(&Name,8,15,BLUE,NCB,"Names may not be blank ",0);
- error = 1;
- }
- }/* end of name check */
- if (!error)
- {
- WWinLoad(&Name,8,15,Name.BackAttr,NC,
- " ",0);
- /* construct full name and put on caption screen */
- strcat(fullname," ");
- strcat(fullname,firstname);
- strcat(fullname," ");
- strcat(fullname,secondname);
- strcat(fullname,"-");
- WWinLoad(&Caption,3,3,NC,NC,
- " ",0); /* clear previous */
- WWinLoad(&Caption,3,3,NC,NC,fullname,0);
- WWinPut(&Caption);
- done = 1;
- }
- }/* while not done */
- }/* end Process */
-
-
-
-
-
- void NameHelp(unsigned char helpitem)
- /* this function sets up the help windows (first time through),
- * asks you to chhose between general and specific help, and
- * (if specific help requested) provides specific help for the active
- * POE.
- */
- {
- /* define the help windows */
- static struct WWinstruc Help[3] = {
- {"ChooseHelp",8,2,11,20, BLUE,WHITE,BLK_BDR,WHITE,BLACK,INV_CSR},
- {"GenHelp",6,15,10,40, BLUE,WHITE,BLK_BDR,WHITE,BLACK,INV_CSR},
- {"DetailHelp",6,10,10,50, BLUE,WHITE,BLK_BDR,WHITE,BLACK,INV_CSR} };
-
- int i, rc, activeitem;
- unsigned int keyin, statin; /* test input key */
- char scan; /* input key scan code */
- struct WWinRC retcde; /* return code strucuture for DoPOE */
- static char setup_switch = 0;
-
- if (!setup_switch)
- {
- for (i=0;i<3;i++)
- if ((rc = WWinDef(&Help[i])) !=0) /* set up help screens */
- {printf("out of memory"); exit(1);}
-
- /* load choosehelp window */
- WWinLoad(&Help[0],1,2,NC,NC,"General Help",0);
- WWinLoad(&Help[0],2,2,NC,NC,"Detail Help",0);
-
- /* load genhelp window */
- WWinLoad(&Help[1],1,2,NC,NC," Enter data and choose OK. ",0);
- WWinLoad(&Help[1],3,2,NC,NC,"Try the arrow keys, tab, or shift-tab",0);
- WWinLoad(&Help[1],4,2,NC,NC,"Try the backspace, delete, and insert",0);
- WWinLoad(&Help[1],5,2,NC,NC,"Try choosing two titles",0);
- WWinLoad(&Help[1],6,2,NC,NC,"Try leaving first or last name blank",0);
- WWinLoad(&Help[1],8,2,NC,NC,"Use shift-arrow keys to move windows",0);
- WWinLoad(&Help[1],10,2,NC,NC,"Press ESC to leave help",0);
-
- /* load some of detail window */
- WWinLoad(&Help[2],1,2,NC,NC,
- "In a real application, this would be help for ",0);
- WWinLoad(&Help[2],5,2,NC,NC,
- " Press ESC to leave help",0);
- setup_switch = 1;
- }/* end setup */
-
- WWinPut(&Help[0]);
- while (1) /* loop forever */
- {
- activeitem = 1; /* vert menu processing */
- do
- {
- retcde = WWinVmenu(&Help[0],BLACK,NC,LOOP,activeitem);
- activeitem = retcde.exval;
- if ( ((retcde.stat & 0x03) != 00) /* Shift key */
- && (retcde.ascii == 0) ) /* control key */
- ShiftWindow(&Help[0],retcde.scan);
- }
- while (retcde.ascii == 0); /* end vert menu processing */
-
- if (retcde.ascii == 27)
- {
- WWinErase(&Help[0]); /* get out */
- return;
- }
-
- /* ENTER pressed - help window chosen */
- if (retcde.exval ==2)
- { /* detail chosen */
- if (helpitem < 6)
- WWinLoad(&Help[2],3,20,NC,NC,"Titles ",0);
- if ( (helpitem > 5) && (helpitem < 8) )
- WWinLoad(&Help[2],3,20,NC,NC,"Names ",0);
- if (helpitem > 7)
- WWinLoad(&Help[2],3,20,NC,NC,"Menu Items",0);
- }
- WWinPut(&Help[retcde.exval]);
- do
- {
- /* get scan code in hi-byte of keyin -- ascii code in lo-byte */
- keyin = _bios_keybrd(_KEYBRD_READ);
- /* get status of ALT,CTL,shift keys, etc. */
- statin = _bios_keybrd(_KEYBRD_SHIFTSTATUS);
- if ((statin & 0x0003) != 00) /* if left or right shift key */
- {
- scan = keyin >> 8; /* scancode in hi-byte */
- ShiftWindow(&Help[retcde.exval],scan);
- }
- }
- while ((keyin & 0x00ff) != 27);
- WWinErase(&Help[retcde.exval]);
- }/* while */
- }/* end NameHelp */
-
-
-
- void ShiftWindow(struct WWinstruc *winptr, unsigned char scan)
- {
- /* this function shifts a window around on the screen, so the user can
- * see things that were hidden.
- * This is an expansion of Sample1 -example1.
- */
- WWinErase(winptr);
- switch(scan)
- {
- case 72: /* up arrow */
- if (winptr->TopRow > 1+(winptr->Border > 0)) winptr->TopRow--;
- break;
- case 80: /* down arrow */
- if (winptr->TopRow + winptr->UseLength-(winptr->Border == 0)
- < WWScreenLength) winptr->TopRow++;
- break;
- case 75: /* left arrow */
- if (winptr->LeftCol > 1+(winptr->Border > 0)) winptr->LeftCol--;
- break;
- case 77: /* right arrow */
- if (winptr->LeftCol + winptr->UseWidth-(winptr->Border == 0)
- < WWScreenWidth) winptr->LeftCol++;
- break;
- default:
- break;
- }
- WWinPut(winptr);
- }/* end shiftwindow */
-
-
-